package com.example.demo.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response<E> {
    private E data;
    private boolean success;
    private int code;
    private String message;
    private long total;


    // 返回成功
    public static <E> Response<E> success(E data){
        Response<E> response = new Response<>();
        response.setData(data);
        response.setSuccess(true);
        return response;
    }

    public static <E> Response<E> success(E data, long total){
        Response<E> response = new Response<>();
        response.setData(data);
        response.setSuccess(true);
        response.setTotal(total);
        return response;
    }

    // 返回失败
    public static <E> Response<E> fail(int code, String message){
        Response<E> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        response.setSuccess(false);
        return response;
    }
}
